package com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.networkassets.dict;

import com.glsc.ngateway.common.base.domain.mysql.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.List;

/**
 * IT网络资产字典根节点
 * @author xuchang
 */
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
@Where(clause = "deleted = 0")
@SQLDelete(sql = "update t_gw_it_net_assets_dict set deleted = UNIX_TIMESTAMP(NOW()) where id=?")
@SQLDeleteAll(sql = "update t_gw_it_net_assets_dict set deleted = UNIX_TIMESTAMP(NOW()) where id=?")
@Table(name = "t_gw_it_net_assets_dict", indexes = {@Index(name = "UK_CODE", columnList = "code, deleted", unique = true),
        @Index(name = "IDX_PARENT_CODE", columnList = "parent_code")})
public class ItNetworkAssetsDict extends BaseEntity {

    private static final long serialVersionUID = 3591061722322610852L;

    @Column(name = "code", columnDefinition = "varchar(128) not null comment 'code'")
    private String code;

    @Column(name = "describtion", columnDefinition = "varchar(128) not null comment '描述'")
    private String describtion;

    @Column(name = "parent_code", columnDefinition = "varchar(128) comment '父节点code，可以为空'")
    private String parentCode;

    /**
     * labelField和valueField供前端使用，决定字典下拉框展示哪个字段，并且前后端传参时，传哪个字段
     */
    @Column(name = "label_field", columnDefinition = "varchar(128) not null comment '前端展示字段'")
    private String labelField;

    @Column(name = "value_field", columnDefinition = "varchar(128) not null comment '前端传参字段'")
    private String valueField;

    /**
     * 层级编号
     */
    @Transient
    private String level;

    /**
     * 子节点
     */
    @Transient
    private List<ItNetworkAssetsDict> children;

    /**
     * 字段
     */
    @Transient
    private List<ItNetworkAssetsDictField> fieldList;
    /**
     * 值
     */
    @Transient
    private List<ItNetworkAssetsDictFieldValue> valueList;
}
